// 防抖
function debounce(func, time) {
    let timer = null;
    return function () {
        clearTimeout(timer)
        timer = setTimeout(() => {
            func.apply(this, arguments)
        }, time)
    }
}

// 截流
function throttle(func, time) {
    let date = 0
    return () => {
        let current = Date.now()
        if (current - date > time) {
            func.apply(this, arguments)
        }
        date = Date.now()
    }
}

// 定时器版本的截流
function throttle2(func, time) {
    let timer = null;
    return function (...args) {
        if (!timer) {
            timer = setTimeout(() => {
                timer = null;
                func.apply(this, args)
            }, time)
        }
    }
}